package com.yanqu.road.server.logic.recharge.limit.activity;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.config.promotion.PromotionInfo;
import com.yanqu.road.entity.mall.LimitBuyResult;
import com.yanqu.road.entity.player.UserCombLeaderData;
import com.yanqu.road.server.gameplayer.module.activity.fund.ActivityFundModule;
import com.yanqu.road.server.gameplayer.module.patrons.CombLeaderModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.config.PromotionMgr;
import com.yanqu.road.server.protocol.GameErrorCode;

public class CombLeaderFundActivityMallLimit extends BaseActivityMallLimit {

    public CombLeaderFundActivityMallLimit(long userId, MallInfo mallInfo, ActivityInfo activityInfo) {
        super(userId, mallInfo, activityInfo);
    }

    @Override
    protected int activityCheck() {
        if (!ActivityMgr.activityInShowTime(activityInfo)) {
            return GameErrorCode.E_ACTIVITY_NO_IN_TIME_CANNOT_BUY;
        }
        return 0;
    }

    @Override
    protected boolean isSystemUnLock() {
        Integer combId = Integer.valueOf(activityInfo.getParam6());
        UserCombLeaderData combLeaderData = player.getModule(CombLeaderModule.class).getUserCombLeaderDataByCombId(combId);
        if (combLeaderData == null || combLeaderData.getLeaderId() == 0) {
            return false;
        }

        PromotionInfo promotionInfo = PromotionMgr.getPromotionInfoById(combLeaderData.getPromoteId());
        if (promotionInfo == null) {
            return false;
        }
        if (promotionInfo.getQuality() >= 5) {
            return true;
        }
        return false;
    }

    @Override
    protected LimitBuyResult buyCountLimit() {
        LimitBuyResult limitBuyResult = new LimitBuyResult();
        limitBuyResult.setLimitCount(1);
        return limitBuyResult;
    }

    @Override
    protected int logicCheck() {
        boolean buyToken = player.getModule(ActivityFundModule.class).isBuy(mallInfo);
        if (buyToken) {
            return GameErrorCode.E_MALL_LIMIT_BUY;
        }
        return 0;
    }

}
